import request from "@/util/request";

const roleMenuUrl = '/permissions/roleMenu/'//请求前缀
const menuUrl = '/permissions/menu/'//请求前缀
/*获取当前用户的菜单信息*/
export function getMYMenus(roleIds) {
    return request({
        method: 'post',
        url: roleMenuUrl + 'getRolesMenus',
        data: roleIds
    })
}

/*获取一些角色的路由信息*/
export function getRoleRouter(roleIds) {
    return request({
        method: 'post',
        url: roleMenuUrl + 'getRouterInfoFromRole',
        data: roleIds
    })
}

export function getAllMenusByPage(pageNum, pageSize, searchMenuDto) {
    return request({
        method: 'get',
        url: menuUrl + 'getAllMenusByPage/' + pageNum + "/" + pageSize,
        params: searchMenuDto
    })
}

export function getAllMenus() {
    return request({
        method: 'get',
        url: menuUrl + 'getAllMenus'
    })
}
export function getAllMenusToTree() {
    return request({
        method: 'get',
        url: menuUrl + 'getAllMenusToTree'
    })
}


export function getMymenuCodes(data) {
    return request({
        method: 'post',
        url: roleMenuUrl + 'get/my/menuCodes/by/roleIds',
        data
    })
}

export function addMenu(data) {
    return request({
        method: 'post',
        url: menuUrl + 'addMenu',
        data
    })
}

export function updateMenu(data) {
    return request({
        method: 'put',
        url: menuUrl + 'updateMenu',
        data
    })
}

export function addRoleMenu(data) {
    return request({
        method: 'post',
        url: roleMenuUrl + 'addRoleMenus',
        data
    })
}

export function getMenusFromRole(id) {
    return request({
        method: 'get',
        url: roleMenuUrl + 'getMenusFromRole/' + id,

    })
}

/**
 * 获取登录人的权限信息
 * @returns {*}
 */
export function getLoginUserPermissions() {
    return request({
        method: 'get',
        url: roleMenuUrl + 'loginUser',
    })
}

export function getPermissionInfo(userId) {
    return request({
        method: 'get',
        url: roleMenuUrl + 'userId',
        params:{
            userId
        }
    })
}
export function deletePermission(id){
    return request({
        method: 'delete',
        url: menuUrl + id,
    })
}

export function getDirectoryPermissionByTree(){
    return request({
        method: 'get',
        url: menuUrl+"directory/tree",
    })
}
